function genChatRankData(name, key, list) {
    var names = [];
    var series = [];

    $.each(list, function (i,d) {
        if (parseFloat(d[key]) > 0) {
            names.push(d.name);
            series.push(getPrice(d[key]));
        }
    });

    return {
        name:name,
        names: names,
        series: series
    };
}

function genChatRankOption(data) {
    let option = {
        tooltip: {
            pointFormat:'{series.name}:<b>{point.y:.2f}</b>',
            trigger: 'axis'
        },
        legend: {
            data: [data.name]
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        xAxis: {
            axisLabel: {
                interval:0, //坐标刻度之间的显示间隔，默认就可以了（默认是不重叠）
                rotate:38   //调整数值改变倾斜的幅度（范围-90到90）
            },
            type: 'category',
            data: data.names
        },
        yAxis: {
            type: 'value'
        },
        series: [{
            name:data.name,
            type: 'bar',
            data: data.series,
        }],
    };

    return option;
}

function genNChatRankOption(data) {
    let option = {
        tooltip: {
            pointFormat:'{series.name}:<b>{point.y:.2f}</b>',
            trigger: 'axis'
        },
        legend: {
            data: [data.labels]
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        xAxis: {
            axisLabel: {
                interval:0, //坐标刻度之间的显示间隔，默认就可以了（默认是不重叠）
                rotate:38   //调整数值改变倾斜的幅度（范围-90到90）
            },
            type: 'category',
            data: data.names
        },
        yAxis: {
            type: 'value'
        },
        series: data.series,
    };

    return option;
}

function genBalanceChatRatioData(name, list) {
    var legendData = [];
    var seriesData = [];
    var selected = {};

    $.each(list, function (i,d) {
        let balance = getPrice(d.balance);
        let label = d.store.name+">"+d.name+"("+balance+"元)";
        legendData.push(label);
        seriesData.push({
            name: label,
            value: balance
        });
        selected[label] = true;
    });

    return {
        name:name,
        legendData: legendData,
        seriesData: seriesData,
        selected: selected
    };
}

function genChatRatioData(name, key, list) {
    var legendData = [];
    var seriesData = [];
    var selected = {};

    $.each(list, function (i,d) {
        if (parseFloat(d[key]) > 0) {
            legendData.push(d.name);
            seriesData.push({
                name: d.name,
                value: getPrice(d[key])
            });
            selected[d.name] = true;
        }
    });

    return {
        name:name,
        legendData: legendData,
        seriesData: seriesData,
        selected: selected
    };
}

function genChatRatioData_all(name, label_end, key, list) {
    var legendData = [];
    var seriesData = [];
    var selected = {};

    $.each(list, function (i,d) {
        let label = d.name+"(" + getPrice(d[key]) + label_end + ")";
        legendData.push(label);
        seriesData.push({
            name: label,
            value: getPrice(d[key])
        });
        selected[label] = true;
    });

    return {
        name:name,
        legendData: legendData,
        seriesData: seriesData,
        selected: selected
    };
}

function genChatRatioOption(data) {
    let option = {
        tooltip: {
            trigger: 'item',
            formatter: '{a} <br/>{b} : {c} ({d}%)'
        },
        legend: {
            type: 'scroll',
            orient: 'vertical',
            right: 10,
            top: 20,
            bottom: 20,
            data: data.legendData,

            selected: data.selected
        },
        series: [
            {
                name: data.name,
                type: 'pie',
                radius: '55%',
                center: ['40%', '50%'],
                data: data.seriesData,
                emphasis: {
                    itemStyle: {
                        shadowBlur: 10,
                        shadowOffsetX: 0,
                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                    }
                }
            }
        ]
    };
    return option;
}

function genChatLineOption(label, names,series) {
    let option = {
        tooltip: {
            pointFormat:'{series.name}:<b>{point.y}</b>',
            trigger: 'axis'
        },
        legend: {
            data: [label]
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        toolbox: {
            feature: {
                saveAsImage: {}
            }
        },
        xAxis: {
            axisLabel: {
                interval:0, //坐标刻度之间的显示间隔，默认就可以了（默认是不重叠）
                rotate:38   //调整数值改变倾斜的幅度（范围-90到90）
            },
            type: 'category',
            data: names
        },
        yAxis: {
            type: 'value'
        },
        series: [{
            name:label,
            type: 'line',
            data: series,
        }],
    };

    return option;
}

function genNChatLineOption(labels, xData,series) {
    let option = {
        tooltip: {
            pointFormat:'{series.name}:<b>{point.y}</b>',
            trigger: 'axis'
        },
        legend: {
            data: labels
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        toolbox: {
            feature: {
                saveAsImage: {}
            }
        },
        xAxis: {
            axisLabel: {
                interval:0, //坐标刻度之间的显示间隔，默认就可以了（默认是不重叠）
                rotate:38   //调整数值改变倾斜的幅度（范围-90到90）
            },
            type: 'category',
            data: xData
        },
        yAxis: {
            type: 'value'
        },
        series: series,
    };

    return option;
}